package 二叉树;

/**
 * TODO
 *
 * @Description
 * @Author Lx
 * @Date 2024/7/3 10:04
 **/
public class 合并二叉树 {
    public static void main(String[] args) {
        
    }

    static public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        if(root1==null&&root2==null)return null;

        TreeNode root;
        if(root1==null) root=root2;
        else if(root2==null) root=root1;
        else root=new TreeNode(root1.val+root2.val);

        root.left=mergeTrees(root1==null?null:root1.left,root2==null?null:root2.left);
        root.right=mergeTrees(root1==null?null:root1.right,root2==null?null:root2.right);

        return root;
    }
}
